package com.superm.controller;

import com.superm.entity.Stock;
import com.superm.service.BrandService;
import com.superm.service.StockService;
import com.superm.service.SupplierService;
import com.superm.service.impl.SupplierServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(path="/stock")
public class StockController {
    @Autowired
    private StockService stockService;
    @Autowired//供应商
    private SupplierService supplierService;
    @RequestMapping(path = "/index")
    public ModelAndView index(Stock inv){
        ModelAndView ma = new ModelAndView();
        System.out.println("sssssssssssssssssssssss");
        System.out.println(inv);
        ma.addObject("supp",supplierService.allSup());
        ma.addObject("inv",inv);
        ma.setViewName("stock/allStock");
        return ma;
    }
    @RequestMapping(path = "/allStock")
    @ResponseBody
    public Map<String,Object> allstock(Stock inv, @RequestParam("page") Integer pageNo, @RequestParam("limit")Integer pageSize){
        Map<String,Object> map =new HashMap<>();
        System.out.println(inv);
        List<Stock> invs = stockService.allstock(inv,pageNo,pageSize);
        //获取总条数
        Integer count = stockService.selectCount(inv);
        System.out.println(count);
        map.put("code",0);
        map.put("count",count);
        map.put("data",invs);
        return map;
    }



    /**
     *异步根据仓库编号查询库存信息
     * @return
     */
    @RequestMapping("/ajaxSelectrIdStock")
    @ResponseBody
    public Map<String,Object> ajaxSelectrIdStock(@RequestParam("rId") Integer rId ){
        Map<String,Object> map = stockService.ajaxStockRepostory(rId);
        return map;
    }

    /**
     *异步根据仓库编号查询库存信息
     * @return
     */
    @RequestMapping("/ajaxSelectrIdStockTwo")
    @ResponseBody
    public Map<String,Object> ajaxSelectrIdStockTwo(@RequestParam("rId") Integer rId ){
        Map<String,Object> map = stockService.ajaxStockRepostoryTwo(rId);
        return map;
    }
    /**
     * 异步根据库存编号查询库存信息
     * @return
     */
    @RequestMapping("/ajaxIdStock")
    @ResponseBody
    public Map<String,Object> ajaxIdStock(@Param("stockId") Integer stockId){
        Map<String,Object> map = stockService.ajaxQueryId(stockId);
        return map;
    }

    /**
     * 异步根据库存编号查询库存信息
     * @return
     */
    @RequestMapping("/ajaxIdStockTwo")
    @ResponseBody
    public Map<String,Object> ajaxIdStockTwo(@Param("stockId") Integer stockId){
        Map<String,Object> map = stockService.ajaxQueryTwo(stockId);
        return map;
    }

}
